package org.lanqiao.music.web.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.lanqiao.music.common.utils.PageHelperResult;
import org.lanqiao.music.common.utils.Result;
import org.lanqiao.music.system.entity.Comment;
import org.lanqiao.music.system.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class CommentController {

    @Autowired
    private CommentService commentService ;
    @GetMapping("/getAll")
    public PageHelperResult getAllComment(Integer musicId)
    {
        PageHelper.startPage(1,100);
        List<Comment> list = commentService.getComment(musicId);
        PageInfo pageInfo = new PageInfo(list);
        PageHelperResult result = PageHelperResult.success(pageInfo);
        return result;
    }
    @PostMapping("/save")
    public Result saveComment(@RequestBody Comment comment)
    {
        if (commentService.save(comment) == 1){
            return Result.success();
        }else
            return Result.fail();
    }

    @GetMapping("/delete")
    public Result deleteComment(Integer musicId,Integer id)
    {
        if (commentService.deleteById(musicId,id) == 1){
            return Result.success();
        }else
            return Result.fail();
    }
}
